#coding=utf-8
'''
# @Name:app
# @author:mysouil
# @Description:
# @DATE:2022/9/23 10:36
# @Modified By:
'''

from flask import Flask
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

app = Flask(__name__)

limiter = Limiter(
    app,
    # 获取客户端的地址
    key_func=get_remote_address,
    # 全局限流
    default_limits=["2 per day", "3 per hour"]
)

@app.route('/hello')
@limiter.limit("1/second",error_message='请求频率太快，请1秒钟后，再试')
@limiter.limit("5/day", error_message='请求频率太快，请1天后，再试')
# @limiter.limit('4 per day')  # 装饰器的限流操作，会覆盖全局的限流
def get_hello():
    return 'hello,world'

if __name__ == '__main__':
    app.run()
